Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.4 KiB

  1. namespace VRTK.Examples
  2. {
  3. using UnityEngine;
  4. public class SnapDropZoneToggle : MonoBehaviour
  5. {
  6. public VRTK_SnapDropZone toggleZoneA;
  7. public VRTK_SnapDropZone toggleZoneB;
  8. protected virtual void OnEnable()
  9. {
  10. toggleZoneA.ObjectEnteredSnapDropZone += ToggleZoneA;
  11. toggleZoneA.ObjectSnappedToDropZone += ToggleZoneA;
  12. toggleZoneA.ObjectExitedSnapDropZone += UntoggleZoneA;
  13. toggleZoneA.ObjectUnsnappedFromDropZone += UntoggleZoneA;
  14. toggleZoneB.ObjectEnteredSnapDropZone += ToggleZoneB;
  15. toggleZoneB.ObjectSnappedToDropZone += ToggleZoneB;
  16. toggleZoneB.ObjectExitedSnapDropZone += UntoggleZoneB;
  17. toggleZoneB.ObjectUnsnappedFromDropZone += UntoggleZoneB;
  18. }
  19. protected virtual void OnDisable()
  20. {
  21. toggleZoneA.ObjectEnteredSnapDropZone -= ToggleZoneA;
  22. toggleZoneA.ObjectSnappedToDropZone -= ToggleZoneA;
  23. toggleZoneA.ObjectExitedSnapDropZone -= UntoggleZoneA;
  24. toggleZoneA.ObjectUnsnappedFromDropZone -= UntoggleZoneA;
  25. toggleZoneB.ObjectEnteredSnapDropZone -= ToggleZoneB;
  26. toggleZoneB.ObjectSnappedToDropZone -= ToggleZoneB;
  27. toggleZoneB.ObjectExitedSnapDropZone -= UntoggleZoneB;
  28. toggleZoneB.ObjectUnsnappedFromDropZone -= UntoggleZoneB;
  29. }
  30. protected virtual void ToggleZoneA(object sender, SnapDropZoneEventArgs e)
  31. {
  32. if (toggleZoneB.GetCurrentSnappedObject() == null)
  33. {
  34. toggleZoneB.gameObject.SetActive(false);
  35. }
  36. }
  37. protected virtual void UntoggleZoneA(object sender, SnapDropZoneEventArgs e)
  38. {
  39. if (toggleZoneA.GetCurrentSnappedObject() == null)
  40. {
  41. toggleZoneB.gameObject.SetActive(true);
  42. }
  43. }
  44. protected virtual void ToggleZoneB(object sender, SnapDropZoneEventArgs e)
  45. {
  46. if (toggleZoneA.GetCurrentSnappedObject() == null)
  47. {
  48. toggleZoneA.gameObject.SetActive(false);
  49. }
  50. }
  51. protected virtual void UntoggleZoneB(object sender, SnapDropZoneEventArgs e)
  52. {
  53. if (toggleZoneB.GetCurrentSnappedObject() == null)
  54. {
  55. toggleZoneA.gameObject.SetActive(true);
  56. }
  57. }
  58. }
  59. }